#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
	{                                         \
		cerr << "\033[32;1m" << #x << " -> "; \
		err(x);                               \
	}
void err()
{
	cerr << "\033[39;0m" << endl;
}
template <typename T, typename... A>
void err(T a, A... x)
{
	cerr << a << ' ';
	err(x...);
}
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 1e5 + 50;

struct segT
{
	int dat[N << 2];
	int lazy[N << 2];
	int nn;
	void init(int a[], int n)
	{
		nn = 1;
		while (nn < n)
			nn <<= 1;
		for (int i = 1; i <= n; ++i)
			dat[i + nn - 1] = a[i];
		
		for (int i = n + nn; i < 2 * nn; ++i)
			dat[i] = 0;
		memset(lazy, 0, sizeof(int) * (2 * nn));
		for (int i = nn - 1; i >= 1; --i)
			pu(i);
	}

	inline void pu(int rt)
	{
		dat[rt] = max(dat[rt << 1], dat[rt << 1 | 1]);
	}

	void trace()
	{
		for (int i=1; i<2*nn; ++i)
			dbg(i, dat[i]);
	}

	inline void pd(int rt)
	{
		if (!lazy[rt])
			return;
		int ls = rt << 1, rs = rt << 1 | 1;
		lazy[ls] += lazy[rt];
		dat[ls] += lazy[rt];
		lazy[rs] += lazy[rt];
		dat[rs] += lazy[rt];
		lazy[rt] = 0;
	}

	int L, R;
	void upt(int l, int r, int rt, int v)
	{
		if (L <= l && r <= R)
		{
			dat[rt] += v;
			lazy[rt] += v;
			return;
		}
		int mid = (l + r) >> 1;
		pd(rt);
		if (L <= mid)
			upt(l, mid, rt << 1, v);
		if (mid + 1 <= R)
			upt(mid + 1, r, rt << 1 | 1, v);
		pu(rt);
	}

	int q(int l, int r, int rt)
	{
		
		// dbg("q", l, r, rt, L, R);
		// if (rt == -1)
		// 	return 0;
		if (L <= l && r <= R)
		{
			return dat[rt];
		}
		int m = (l + r) >> 1;
		pd(rt);
		int v = 0;
		if (L <= m)
			v = max(v, q(l, m, rt << 1));
		if (m + 1 <= R)
			v = max(v, q(m + 1, r, rt << 1 | 1));
		pu(rt);
		return v;
	}

	void u(int l, int r, int v)
	{
		L = l;
		R = r;
		upt(1, nn, 1, v);
	}

	inline int q(int l, int r)
	{
		L = l;
		R = r;
		return q(1, nn, 1);
	}
} seg;

int n, s, a[N];
int b[N], first[N], rnk[N];
int disc[N], dcnt;

vector<int> p[N];

int main(int argc, char const *argv[])
{
	int t;
	scanf("%d", &t);
	for (int kk = 1; kk <= t; ++kk)
	{
		scanf("%d%d", &n, &s);
		for (int i = 1; i <= n; ++i)
			scanf("%d", &a[i]);
		dcnt = 0;
		for (int i = 1; i <= n; ++i)
			disc[dcnt++] = a[i];
		sort(disc, disc + dcnt);
		dcnt = unique(disc, disc + dcnt) - disc;
		for (int i = 1; i <= n; ++i)
			a[i] = lower_bound(disc, disc + dcnt, a[i]) - disc + 1;

		for (int i = 1; i <= n; ++i)
		{
			p[i].clear();
		}
		for (int i = 1; i <= n; ++i)
		{
			rnk[i] = p[a[i]].size() + 1;
			p[a[i]].push_back(i);
		}

		for (int i=1; i<=n; ++i)
		{
			if (!first[a[i]])
			{
				first[a[i]] = rnk[i];
			}
			b[i] = 1;
			if (rnk[i] - first[a[i]] == s)
			{
				b[i] = -s;
			} 
			else if (rnk[i] - first[a[i]] > s)
			{
				b[i] = 0;
			}
			b[i] += b[i-1];
			
			// dbg(i, b[i]);
		}

		seg.init(b, n);
		int ans = seg.q(1, n);
		
		for (int i=1; i<n; ++i)
		{
			// for (int j=1; j<=n; ++j)
			// 	dbg(j, seg.q(j, j));
			seg.u(i, n, -1);
			if (rnk[i] + s - 1 < p[a[i]].size())
				seg.u(p[a[i]][rnk[i] + s - 1], n, s + 1);
			if (rnk[i] + s < p[a[i]].size())
				seg.u(p[a[i]][rnk[i] + s], n, -s);
			// dbg(i);
			ans = max(ans, seg.q(1, n));
		}

		

		printf("Case #%d: %d\n", kk, ans);
		// return 0;
	}
	return 0;
}